package web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/loginFailServlet")
public class LoginFailServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setContentType("text/html;charset=utf-8");

        //向页面响应一个登录失败的提示
        PrintWriter writer = resp.getWriter();
        writer.write("<!DOCTYPE html>");
        writer.write("<html lang=\"en\">");
        writer.write("<head>\n" +
                "    <meta charset=\"UTF-8\">\n" +
                "    <title>Title</title>\n" +
                "</head>\n" +
                "<body>\n" +
                "\n" +
                "<form action=\"/demo2/loginServlet\" method=\"post\">\n" +
                "    username: <input type=\"text\" name=\"username\">");

        writer.write("<span style=\"color: red;\">"+req.getAttribute("msg")+"</span>");

        writer.write("<br>\n" +
                "    password: <input type=\"password\" name=\"password\"> <br>\n" +
                "\n" +
                "    <input type=\"submit\" value=\"登录\">\n" +
                "</form>\n" +
                "\n" +
                "</body>\n" +
                "</html>");
    }

}
